package com.aloda.controller.user;

import com.aloda.dto.UserEditInfoDTO;
import com.aloda.result.Result;
import com.aloda.service.UserService;
import com.aloda.vo.UserEditVO;
import com.aloda.vo.UserInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userUserController")
@RequestMapping("/user/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 获取用户页面个人信息
     * @param id
     * @return
     */
    @GetMapping("/info")
    public Result<UserInfoVO> getUserInfo(@RequestParam Long id){
        log.info("用户{}页面个人信息显示",id);
        UserInfoVO userInfoVO = userService.getUserInfo(id);
        return Result.success(userInfoVO);
    }

    /**
     * 用户编辑页面信息回显
     * @return
     */
    @GetMapping("/editInfo")
    public Result<UserEditVO> getEditInfo(){
        UserEditVO userEditVO = userService.getEditInfo();
        return Result.success(userEditVO);
    }

    /**
     * 用户编辑个人信息
     * @return
     */
    @PutMapping("/edit")
    public Result editUser(@RequestBody UserEditInfoDTO userEditInfoDTO){
        log.info("编辑个人信息：{}",userEditInfoDTO);
        userService.editUser(userEditInfoDTO);
        return Result.success();
    }
}
